
imagePreview = function(){	
	xOffset = 10;
	yOffset = 30;	
	
	imgDiv = 2;

  	// Callback que llama cada vez hace hover
	$("a.preview").hover(function(e){  	
	  	var img = new Image();		
	  	$("#preview-image").remove();	  	
	  	$("body").append('<div id="preview-image" style="display: none; position: absolute; z-index: 20000000;"></div>');	  	
	  	var iml = this.href;	
		
		$("#preview-image").html('');
			
		$(img)		
		  .load(function(){
				$(this).hide();
				$("#preview-image")
				  .html('')
				  .append(this);
	
				var imageInPreview = $("#preview-image").children();
			
				// adjust the width and height attributes
				if (img.width > ($(window).width())/2 && img.height > ($(window).height())/2){
					
					xDif = (img.width - $(window).width());					
					yDif = (img.width - $(window).height());
					if (xDif > yDif) {
					
						img.width = ($(window).width()-($(window).width()/2));
						imageInPreview.width(img.width);
					} else {	
					
						img.height = ($(window).height() - ($(window).height()/2))
						imageInPreview.height(img.height);
					}
				} else if (img.width > ($(window).width())/2){
					
					img.width = ($(window).width() - ($(window).width()/2))
					imageInPreview.width(img.width);
				} else if (img.height > ($(window).height())/2){
					
					img.height = ($(window).height() - ($(window).height()/2))
					imageInPreview.height(img.height);
				} 
				
				
				$(this).fadeIn("fast");				
				
				pleft = e.pageX + yOffset;
				ptop = e.pageY - xOffset;									
				
				if ((pleft + img.width) > $(window).width()){
					pleft = e.pageX - img.width - yOffset;
				}
				
				$("#preview-image")
					.css("top",ptop + "px")
					.css("left",pleft + "px");										
				
		 });
		$(img).attr('src', iml);
		$("#preview-image").show();
		
	}, function(){
		$("#preview-image").hide();
		$("#preview-image").remove();
	});
	
  
  	// Callback que llama cada vez que mueve el mouse
  	$("a.preview").mousemove(function(e){
		
		var pleft = e.pageX + yOffset;
		var ptop = e.pageY - xOffset;				
		var imgWidth = $("#preview-image").width();
		
		if ((pleft + imgWidth) > $(window).width()){
			pleft = e.pageX - imgWidth - yOffset;
		}
		
		$("#preview-image")
			.css("top",ptop + "px")
			.css("left",pleft + "px");
	});	
		
};